package com.leizi.igym.resp;

import com.leizi.igym.enums.ReturnCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: leizi0110
 * @CreateTime: 2024-03-29  23:13
 * @Description:
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    //  返回状态码
    private int code;

    //  返回信息
    private String msg;

    //  返回体
    private T data;

    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>();
        result.setCode(ReturnCodeEnum.RC20000.getCode());
        result.setMsg(ReturnCodeEnum.RC20000.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> ok() {
        return Result.ok(null);
    }

    public static <T> Result<T> ok(int code, String msg, T data) {
        Result<T> result = new Result<>(code, msg, data);
        return result;
    }


    public static <T> Result<T> fail(T data) {
        Result<T> result = new Result<>();
        result.setCode(ReturnCodeEnum.RC500.getCode());
        result.setMsg(ReturnCodeEnum.RC500.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(int code, String msg, T data) {
        Result<T> result = new Result<>(code, msg, data);
        return result;
    }

    public static <T> Result<T> fail() {
        return Result.fail(null);
    }

    public static <T> Result<T> fail(int code, String msg) {
        Result<T> result = new Result<>(code, msg, null);
        return result;
    }

    public static <T> Result<T> fail(ReturnCodeEnum returnCodeEnum, String msg) {
        Result<T> result = new Result<>(returnCodeEnum.getCode(), msg, null);
        return result;
    }
}
